//
//  ByNiticeCell.m
//  jmsfhz_ios
//
//  Created by pro on 16/7/19.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "ByNiticeCell.h"

@implementation ByNiticeCell

+ (instancetype)createCellInTableview:(UITableView *)table {
    
    static NSString *cellIdentifier = @"ByNiticeCell";
    ByNiticeCell *cell = [table dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style
              reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor clearColor];
        [self initSubviews];
    }
    return self;
}

- (void)initSubviews {
    
    CGFloat x, y, width, height;
    /** 时间 */
    x = 0;
    y = 20;
    width = 200;
    height = 25;
    self.dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    self.dateLabel.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1];
    self.dateLabel.textColor = [UIColor darkGrayColor];
    self.dateLabel.font = FONT(14);
    self.dateLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.dateLabel];
    self.dateLabel.text = @"2016年7月7号";
    self.dateLabel.width = [self.dateLabel.text getSizeOfString:14].width + 20;
    self.dateLabel.center = CGPointMake(SCREEN_WIDTH / 2, self.dateLabel.center.y);
    self.dateLabel.layer.cornerRadius = 4;
    
    /** 背景视图 */
    x = 15;
    y = self.dateLabel.bottom + 20;
    width = SCREEN_WIDTH - x * 2;
    height = 0;
    UIView *basalView = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)];
    [self.contentView addSubview:basalView];
    basalView.backgroundColor = [UIColor whiteColor];
    basalView.layer.cornerRadius = 10;
    
    /** 图片 */
    x = 10;
    y = 10;
    width = (basalView.width - 2 * x);
    height = width / 2;
    self.contentImageView = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, width, height)];
    self.contentImageView.image = [UIImage imageNamed:@"defaultImage2"];
    [basalView addSubview:self.contentImageView];
    
    /** 线 */
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, self.contentImageView.bottom + 10, basalView.width, 1)];
    line.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1];
    [basalView addSubview:line];
    
    /** 内容 */
    x = self.contentImageView.left;
    y = line.bottom + 10;
    width = self.contentImageView.width;
    height = 50;
    self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    self.contentLabel.textColor = [UIColor blackColor];
    self.contentLabel.font = FONT(14);
    self.contentLabel.textAlignment = NSTextAlignmentLeft;
    self.contentLabel.numberOfLines = 2;
    [basalView addSubview:self.contentLabel];
    self.contentLabel.text = @"这是一个公告这是一个公告这是一个公告这是一个公告这是一个公告这是一个公告这是一个公告这是一个公告这是一个公告这是一个公告";
    
    basalView.height = self.contentLabel.bottom;
}

- (void)setModel:(ByNetNewsItemModel *)model {
    
    _model = model;
    
    self.contentLabel.text = _model.post_title;
    [self.contentImageView setImageWithURL:[NSURL URLWithString:_model.main_img] placeholderImage: [UIImage imageNamed:@"defaultImage2"]];
    self.dateLabel.text = _model.post_date;
    self.dateLabel.width = [self.dateLabel.text getSizeOfString:14].width + 20;

}

@end
